package com.qsl.ssyx.home.service.impl;

import com.qsl.ssyx.client.product.ProductFeignClient;
import com.qsl.ssyx.client.search.SkuFeignClient;
import com.qsl.ssyx.client.user.UserFeignClient;
import com.qsl.ssyx.home.service.HomeService;
import com.qsl.ssyx.model.product.Category;
import com.qsl.ssyx.model.product.SkuInfo;
import com.qsl.ssyx.model.search.SkuEs;
import com.qsl.ssyx.vo.user.LeaderAddressVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class HomeServiceImpl implements HomeService {

    @Autowired
    private UserFeignClient userFeignClient;

    @Autowired
    private ProductFeignClient productFeignClient;

    @Autowired
    private SkuFeignClient skuFeignClient;

    // 首页数据显示-微信小程序
    @Override
    public Map<String, Object> homeData(Long userId) {
        // 最终返回数据
        HashMap<String, Object> result = new HashMap<>();
        System.out.println("========>userId: " + userId);
        // 根据用户id获取当前登录用户提货地址信息
        LeaderAddressVo leaderAddressVo = userFeignClient.getUserAddressByUserId(userId);
        result.put("leaderAddressVo", leaderAddressVo);

        System.out.println("============>leaderAddressVo: " +leaderAddressVo);

        // 获取新人专享商品
        List<SkuInfo> newPersionSkuInfoList = productFeignClient.findNewPersionSkuInfoList();
        result.put("newPersonSkuInfoList", newPersionSkuInfoList);

        // 获取所有商品分类信息
        List<Category> categoryList = productFeignClient.findCategoryList();
        result.put("categoryList", categoryList);

        // 获取10件爆款商品（热销好货）-ES里获取
        List<SkuEs> hotSkuList = skuFeignClient.findHotSkuList();
        result.put("hotSkuList", hotSkuList);

        return result;
    }
}
